package edu.syr.iis.web.model;


import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

@Entity
public class Assignment {	
	public static final int ASSIGNED = 0;
	public static final int COMPLETED = 1;
		
	int assignmentId;	
	
	User user;
	Conversation conversation;
	int status = ASSIGNED;
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public int getAssignmentId() {
		return assignmentId;
	}
	
	public void setAssignmentId(int assignmentId) {
		this.assignmentId = assignmentId;
	}
	
	@ManyToOne
	@JoinColumn(name="userId")
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}

	@ManyToOne
	@JoinColumn(name="conversationId")
	public Conversation getConversation() {
		return conversation;
	}
	public void setConversation(Conversation conversation) {
		this.conversation = conversation;
	}
	
	@Basic
	public int getStatus() {
		return status;
	}
	public void setStatus(int status) {
		this.status = status;
	} 		
	
	@Transient
	public double getAverageAgreement() 
	{		
		return conversation.getAverageAgreement(user); 
	}

	@Transient
	public double getAverageFunctionAgreement() 
	{		
		return conversation.getAverageFunctionAgreement(user); 
	}

	
	@Transient
	public String getAverageAgreementString() 
	{		
		return conversation.getAverageAgreementString(user); 
	}

	@Transient
	public String getAverageFunctionAgreementString() 
	{		
		return conversation.getAverageFunctionAgreementString(user); 
	}
	
	@Transient
	public String getMessageWiseAgreementString() 
	{		
		return conversation.getMessageWiseAgreementString(user); 
	}

	@Transient 
	public int getNumAnnotated() {
		return conversation.getNumAnnotated(user);
	}
	
	@Transient 
	public String getProgressEstimate () {
		double estimate = ((double) getNumAnnotated()) / conversation.getNumMessages();
		long percentile = Math.round(estimate * 100);
		return  percentile + "%";
	}
	
	
	public String toLogString()
	{
		return "assignmentId:   " + assignmentId + "\n" +
		       "userName:       " + user.userName + "\n" +
		       "conversationId: " + conversation.conversationId + "\n" +
		       "status:         " + status;
	}
}
